package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BieHouseholder;
import com.ruoyi.system.service.IBieHouseholderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 住户Controller
 * 
 * @author zxl
 * @date 2021-05-03
 */
@RestController
@RequestMapping("/system/householder")
public class BieHouseholderController extends BaseController
{
    @Autowired
    private IBieHouseholderService bieHouseholderService;

    /**
     * 查询住户列表
     */
    @PreAuthorize("@ss.hasPermi('system:householder:list')")
    @GetMapping("/list")
    public TableDataInfo list(BieHouseholder bieHouseholder)
    {
        startPage();
        List<BieHouseholder> list = bieHouseholderService.selectBieHouseholderList(bieHouseholder);
        return getDataTable(list);
    }

    /**
     * 导出住户列表
     */
    @PreAuthorize("@ss.hasPermi('system:householder:export')")
    @Log(title = "住户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BieHouseholder bieHouseholder)
    {
        List<BieHouseholder> list = bieHouseholderService.selectBieHouseholderList(bieHouseholder);
        ExcelUtil<BieHouseholder> util = new ExcelUtil<BieHouseholder>(BieHouseholder.class);
        return util.exportExcel(list, "住户数据");
    }

    /**
     * 获取住户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:householder:query')")
    @GetMapping(value = "/{holderId}")
    public AjaxResult getInfo(@PathVariable("holderId") String holderId)
    {
        return AjaxResult.success(bieHouseholderService.selectBieHouseholderById(holderId));
    }

    /**
     * 新增住户
     */
    @PreAuthorize("@ss.hasPermi('system:householder:add')")
    @Log(title = "住户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BieHouseholder bieHouseholder)
    {
        return toAjax(bieHouseholderService.insertBieHouseholder(bieHouseholder));
    }

    /**
     * 修改住户
     */
    @PreAuthorize("@ss.hasPermi('system:householder:edit')")
    @Log(title = "住户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BieHouseholder bieHouseholder)
    {
        return toAjax(bieHouseholderService.updateBieHouseholder(bieHouseholder));
    }

    /**
     * 删除住户
     */
    @PreAuthorize("@ss.hasPermi('system:householder:remove')")
    @Log(title = "住户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{holderIds}")
    public AjaxResult remove(@PathVariable String[] holderIds)
    {
        return toAjax(bieHouseholderService.deleteBieHouseholderByIds(holderIds));
    }
}
